#include <gtest/gtest.h>
#include "core/regions/end_point.h"

using namespace aliyun;

TEST(core_regions, Endpoint) {
  std::vector<string> region_ids;
  region_ids.push_back("cn-hangzhou-1");

  std::vector<ProductDomain> product_domains;
  product_domains.push_back(ProductDomain("TestProduct", "testproduct.aliyuncs.com"));

  Endpoint end_point("cn-hangzhou", region_ids, product_domains);

  ASSERT_STREQ("cn-hangzhou", end_point.GetName().c_str());
  end_point.SetName("cn-shenzhen");
  ASSERT_STREQ("cn-shenzhen", end_point.GetName().c_str());

  ASSERT_EQ((size_t)1, end_point.GetRegionIds().size());
  ASSERT_STREQ("cn-hangzhou-1", end_point.GetRegionIds()[0].c_str());
  region_ids.clear();
  region_ids.push_back("cn-hangzhou-2");
  region_ids.push_back("cn-hangzhou-3");
  end_point.SetRegionIds(region_ids);
  ASSERT_EQ((size_t)2, end_point.GetRegionIds().size());
  ASSERT_STREQ("cn-hangzhou-2", end_point.GetRegionIds()[0].c_str());
  ASSERT_STREQ("cn-hangzhou-3", end_point.GetRegionIds()[1].c_str());

  ASSERT_EQ((size_t)1, end_point.GetProductDomains().size());
  ASSERT_STREQ("TestProduct", end_point.GetProductDomains()[0].GetProductName().c_str());
  ASSERT_STREQ("testproduct.aliyuncs.com", end_point.GetProductDomains()[0].GetDomainName().c_str());
  product_domains.clear();
  product_domains.push_back(ProductDomain("TestProduct1", "testproduct1.aliyuncs.com"));
  product_domains.push_back(ProductDomain("TestProduct2", "testproduct2.aliyuncs.com"));
  end_point.SetProductDomains(product_domains);
  ASSERT_EQ((size_t)2, end_point.GetRegionIds().size());
  ASSERT_STREQ("TestProduct1", end_point.GetProductDomains()[0].GetProductName().c_str());
  ASSERT_STREQ("testproduct1.aliyuncs.com", end_point.GetProductDomains()[0].GetDomainName().c_str());
  ASSERT_STREQ("TestProduct2", end_point.GetProductDomains()[1].GetProductName().c_str());
  ASSERT_STREQ("testproduct2.aliyuncs.com", end_point.GetProductDomains()[1].GetDomainName().c_str());
}


// end of file
